<?php

/**
 * @author 		Samuel Carlier
 * @package 	P3Base_Mailer
 * @subpackage 	P3Base_Mailer_Iterator
 */
class P3Base_Mailer_Iterator_MailAddress extends P3Base_Iterator_Simple {

	/**
	 * @return string
	 */
	public function current() {
		$current = current($this->_array);
		if(!isset($current['email'])) {
			return;
		}

		$current['name']  = str_replace(array("\n", "\r", "\t"), '', $current['name']);
		$current['email'] = str_replace(array("\n", "\r", "\t"), '', $current['email']);

		$str = '';
		if(isset($current['name'])) {
			$str = '"' . $current['name'] . '"';
		}

		return $str . '<' . $current['email'] . '>';
	}
	
	/**
	 * @return string
	 */
	public function key() {
		$current = current($this->_array);
		if(!isset($current['email'])) {
			return;
		}
		
		return '<' . $current['email'] . '>';
	}
}
?>
